/**************************************************************************
 *         Copyright(c) 2007 by Sunplus mMedia  Technology Co., Ltd.       *
 *                                                                         *
 *  This software is copyrighted by and is the property of Sunplus mMedia  *
 *  Technology Co., Ltd. All rights are reserved by Sunplus mMedia Techno- *
 *  logy Co., Ltd. This software may only be used in accordance with the   *
 *  corresponding license agreement. Any unauthorized use, duplication,    *
 *  distribution, or disclosure of this software is expressly forbidden.   *
 *                                                                         *
 *  This Copyright notice "M U S T" not be removed or modified without     *
 *  prior written consent of Sunplus mMedia Technology  Co., Ltd.          *
 *                                                                         *
 *  Sunplus mMedia Technology Co., Ltd. reserves the right to modify this  *
 *  software without notice.                                               *
 *                                                                         *
 *  Sunplus mMedia Technology Co., Ltd.                                    *
 *  19-1, Innovation First Road, Science-Based Industrial Park,            *
 *  Hsin-Chu, Taiwan, R.O.C.                                               *
 *                                                                         *
 **************************************************************************/
#include "general.h"
#include "solution.h"
#include "app_main.h"
#include "os_msg.h"
#include "initio.h"
#include "app_video_view.h"
#include "app_menu.h"
#include "app_menu_micro.h"
#include "app_osd_icon.h"
#include "app_menu_api.h"
#include "App_ui_para.h"
#include "app_ui_osd.h"
#include "app_ui_power.h"
#include "app_menu_tab.h"
#include "sp1k_aud_api.h"
#include "sp1k_pv_api.h"
#include "sp1k_disp_api.h"
#include "sp1k_aaa_api.h"
#include "sp1k_video_api.h"
#include "sp1k_hal_api.h"
#include "sp1k_util_api.h"
#include "sp1k_vfs_api.h"
#include "sp1k_osd_api.h"
#include "key_scan.h"
#include "app_menu_core.h"
#include "cardlink.h"
#include "dpf_scan.h"
#include "smcfunc.h"
/**************************************************************************
 *                           C O N S T A N T S                            *
 **************************************************************************/
#define AWB_SPEED 2
#define AWB_SPEED_FAST_ONCE 255

#define APP_PCM_FMT		0
#define APP_ADPCM_FMT	1
#define APP_AUDIO_FMT    APP_PCM_FMT
/**************************************************************************
 *                              M A C R O S                               *
 **************************************************************************/

/**************************************************************************
 *                          D A T A    T Y P E S                          *
 **************************************************************************/

/**************************************************************************
 *						   G L O B A L	  D A T A						  *
 **************************************************************************/
UINT16 xdata video_zoomFactor = 100;
UINT8 xdata video_zoomInFlag = 0;
UINT8 xdata video_zoomOutFlag = 0;
//UINT16 xdata  zoomStep=0;
UINT16 ZoomCurLog = 100; // hlc 0328 improve zoom quality

/**************************************************************************
 *				   E X T E R N A L	  R E F E R E N C E S				  *
 **************************************************************************/
//extern void appStillViewZoomFactorSet(UINT16 value);
extern UINT8 appElecFreqSet(void);
extern UINT16 pvWaitCnt;
#if LIFE_SPAN_TEST
extern UINT8 vidClipRdy;
#endif
UINT8 appStillViewAEAWBWait(void);

/**************************************************************************
 *				 F U N C T I O N	D E C L A R A T I O N S 			  *
 **************************************************************************/

void appVideoView (UINT8 msg) USING_0
{
//	powerBatLv_t batlv;
	static UINT8 cardErrFmt = 0;

	

	//zhenglei add for S2 Release and  save rec file
	if (msg == 0x21)
	{	
		msg = SP1K_MSG_KEY_PRESS_S2;	
	}

	switch (msg) {
		
		case SP1K_MSG_STATE_INIT:
			printf("video init.\n");
			//jintao.liu 2008-3-15 add for video quality
			appVideoQualitySet();
			appAutoOffTimeSet();//jintao.liu 2008-3-28 add for mantis 21604
			appElecFreqSet();//jintao.liu 2008-3-31 add for electronic freq
			appVideoFrmRateSet();//jintao.liu 2008-4-22
			sp1kVideoRecAudSampleRateSet(22050);
			appVideoViewInit(SP1K_VIDEO_VIEW_INIT_FULL);
			break;
		case SP1K_MSG_KEY_PRESS_S1:
			break;
		case SP1K_MSG_KEY_PRESS_S2:
			pvWaitCnt = 0;
			if(sp1kVideoRecStatusGet() == VID_REC_IDLE) {
				printf("zhenglei....video rec S2 Press...0\n");
				osMsgPost(SP1K_MSG_3A_WAIT_PROC);
			}	
			else {
				printf("zhenglei....video rec S2 Press...1\n");
				osMsgPost(SP1K_MSG_MEDIA_REC_STOP);
			}
			break;
		case SP1K_MSG_3A_WAIT_PROC:			
			if (appStillViewAEAWBWait() != SUCCESS) {
				break;
			}
		case SP1K_MSG_MEDIA_REC_STOP:
			#if(TV_OPTION == TV_PLAY_OPTION)
			if(appPanelTypeGet() == 0) {
				break;
			}
			#endif

#ifdef _ENABLE_LCD_OFF_
				appOsdModeSw(0);
#endif /*_ENABLE_LCD_OFF_*/


			#if (!NAND_SUPPORT)//2008-7-14 mantis #28129
			if(0 == appSDPlugStatusGet())
			{
				uiOsdDialogDisp(ID_STR_NO_CARD_, 1000);
				appVideoOsdInit();
				break;
			}
			#endif
			if(1 == appSDProtectStatusGet())//jintao.liu 2008-5-6 for sd lock
			{
				uiOsdDialogDisp(ID_STR_CARD_LOCKED_, 1000);
				appVideoOsdInit();
				break;
			}
			
			//sp1KAWBScaleSet(SP1K_AWB_Jump_Scale, AWB_SPEED_FAST_ONCE);// force awb jump to target
			appVideoSnap();
			if(sp1kVideoRecStatusGet() != VID_REC_IDLE) {
				appAutoOffEn(0);
			}
			break;
    	case SP1K_MSG_KEY_PRESS_MENU:
			if(sp1kVideoRecStatusGet() == VID_REC_IDLE) {
				//appVideoSnap();
				osMsgPost(SP1K_MSG_STATE_TO_MENU);
			}
			//printf("menu\n");
			break;
    	case SP1K_MSG_KEY_PRESS_UP:
			if (1 == cardErrFmt)
			{
				menuProcMoveUp();
				menuProcDisp();
				break;
			}

			if(sp1kVideoRecStatusGet() == VID_REC_IDLE)
			{
				uiPara_t* puiPara;
				puiPara = appUiParaGet();
				puiPara->VideoSize++;

				if (MOV_SIZE_QVGA_HFR == puiPara->VideoSize)
					puiPara->VideoSize = MOV_SIZE_D1;

				osMsgPost(SP1K_MSG_STATE_INIT);//2008-7-9 mantis #27830
			}
			else
			{
				appVideoPauseProcess();
			}
			//printf("up\n");
			break;
    	case SP1K_MSG_KEY_PRESS_DOWN:
			//printf("down\n");
			if (1 == cardErrFmt)
			{
				menuProcMoveDown();
				menuProcDisp();
			}
			break;
		case SP1K_MSG_KEY_PRESS_OK:
			if (1 == cardErrFmt)
			{
				UINT32 menuPos;

				menuPos = menuProcCurrPosGet();
				if (menuPos == MENU_MARK_FORMAT_YES)
				{
					if(1 == appSDProtectStatusGet())
					{
						uiOsdDialogDisp(ID_STR_CARD_LOCKED_, 1000);
						//menuExit();
						return;
					}

					appUiBusyWait(250, 1);
					STORAGE_Format(0xC1);//format
					M_Card_Initialize(1);// initialization
					G_USR_FileIndex = 1; //DCF Init
					cardErrFmt = 0;
					appUiBusyExit();
					uiRemainPixInit();
					appVideoViewInit(SP1K_VIDEO_VIEW_INIT_FULL);
				}
				else
				{
					uiOsdDialogDisp(ID_STR_PLEASE_PLUG_OUT_CARD, 0);
					sp1kBtnDisableAll();
				}
			}
#ifdef _ENABLE_LCD_OFF_
			else
			{
				if(sp1kVideoRecStatusGet() == VID_REC_IDLE) {
					appOsdModeSw(1);
				}
			}
#endif /*_ENABLE_LCD_OFF_*/
			break;
    	case SP1K_MSG_KEY_PRESS_LEFT:
			if(sp1kVideoRecStatusGet() != VID_REC_IDLE) {
				//appVideoSnap();
			}
			if(sp1kVideoRecStatusGet() == VID_REC_IDLE) {
				sp1kAudioRecTypeSet(AUDIO_TYPE_NORMAL);
				osMsgPost(SP1K_MSG_STATE_TO_AUDIO_REC);
			}
			//printf("left\n");
			break;
    	case SP1K_MSG_KEY_PRESS_RIGHT:
			//printf("right\n");
			break;
    	case SP1K_MSG_KEY_PRESS_F1:
			break;
  	  	case SP1K_MSG_KEY_PRESS_TELE:
#ifdef _ENABLE_LCD_OFF_
			appOsdModeSw(0);
#endif /*_ENABLE_LCD_OFF_*/
			sp1kAeModeSet(0); // hlc, stops 3A when zoom
			sp1kAwbModeSet(SP1K_AWB_MODE_DISABLE);
			break;
		case SP1K_MSG_KEY_REPEATE_TELE:
			appVideoViewTele();
			if(sp1kVideoRecStatusGet() == VID_REC_IDLE) {
				sp1kVideoRecZoomFacSet(video_zoomFactor, 0);
			} else {
				sp1kVideoRecZoomFacSet(video_zoomFactor, 1);
			}
			break;
		case SP1K_MSG_KEY_PRESS_WIDE:
#ifdef _ENABLE_LCD_OFF_
			appOsdModeSw(0);
#endif /*_ENABLE_LCD_OFF_*/
			sp1kAeModeSet(0);
			sp1kAwbModeSet(SP1K_AWB_MODE_DISABLE);
			break;
		case SP1K_MSG_KEY_REPEATE_WIDE:
			appVideoViewWide();
			if(sp1kVideoRecStatusGet() == VID_REC_IDLE) {
				sp1kVideoRecZoomFacSet(video_zoomFactor, 0);
			} else {
				sp1kVideoRecZoomFacSet(video_zoomFactor, 1);
			}
			break;
		case SP1K_MSG_KEY_RELEASE_TELE:
			appVideoViewTele();
			if(sp1kVideoRecStatusGet() == VID_REC_IDLE) {
				sp1kVideoRecZoomFacSet(video_zoomFactor, 0);
			} else {
				sp1kVideoRecZoomFacSet(video_zoomFactor, 1);
			}
			sp1kAeModeSet(1);
			sp1kAwbModeSet(SP1K_AWB_MODE_CONTINUE);
			break;
		case SP1K_MSG_KEY_RELEASE_WIDE:
			appVideoViewWide();
			if(sp1kVideoRecStatusGet() == VID_REC_IDLE) {
				sp1kVideoRecZoomFacSet(video_zoomFactor, 0);
			} else {
				sp1kVideoRecZoomFacSet(video_zoomFactor, 1);
			}
			sp1kAeModeSet(1);
			sp1kAwbModeSet(SP1K_AWB_MODE_CONTINUE);
			break;
		case SP1K_MSG_KEY_PRESS_DISP:
			//printf("disp\n");
			break;
		case SP1K_MSG_KEY_PRESS_PB:
			if(sp1kVideoRecStatusGet() != VID_REC_IDLE) {
				appVideoSnap();
			}
			if(sp1kVideoRecStatusGet() == VID_REC_IDLE) {
			osMsgPost(SP1K_MSG_STATE_TO_STILL_PLAY);
			}
			break;
		case SP1K_MSG_CARD_PLUG_IN:
			appStorageMount(K_MEDIA_SDF);
			uiRemainPixInit();
			appVideoOsdInit();
			break;
		case SP1K_MSG_CARD_PLUG_OUT:
			cardErrFmt = 0;
			sp1kBtnEnableAll();
			sp1kOsdSelWinSet(-1, -1, -1, -1, 0, -1);//jintao.liu 2008-6-13 mantis #25594
			appStorageMount(K_MEDIA_NANDF);
			uiRemainPixInit();
			appVideoOsdInit();
			//add for mantis #36294@start
			if((appSDPlugStatusGet()==0) && (sp1kDiskTypeGet()==DEV_TYPE_DISK_SPI))
			{
				osMsgFlush();
				uiOsdDialogDisp(ID_STR_NO_CARD_, 0);
			}
			//add for mantis #36294@end
			
			//osMsgFlush();
			//uiOsdDialogDisp(ID_STR_NO_CARD_, 0);
			break;
		case SP1K_MSG_USB_PLUG_IN:
			if(sp1kVideoRecStatusGet() != VID_REC_IDLE){
				//appVideoSnap();
				sp1kVideoRecStop();
				uiUpdateVideoStatus(0, sp1kVideoRecStatusGet());
			}
			if (storageReadyflag==SUCCESS) {
				if (0)//(USB_DBG) //zhenglei
				{
					sp1kHalUSBSwPlugIn();
				} else {
					osMsgPost(SP1K_MSG_STATE_TO_USB);
				}
			}
			break;
		case SP1K_MSG_USB_PLUG_OUT:
			break;

		case SP1K_MSG_TV_PLUG_IN:
#if(TV_OPTION == TV_PLAY_OPTION)
			osMsgPost(SP1K_MSG_STATE_TO_STILL_PLAY);
			osMsgPost(SP1K_MSG_TV_PLUG_IN);
#elif (TV_OPTION == TV_FULL_OPTION)
			if(sp1kVideoRecStatusGet() != VID_REC_IDLE) {
				//appVideoSnap();
				sp1kVideoRecStop();
				uiUpdateVideoStatus(0, sp1kVideoRecStatusGet());
			}
			if(sp1kVideoRecStatusGet() == VID_REC_IDLE) {
				appDispSet();
			}
#endif
			break;
		case SP1K_MSG_TV_PLUG_OUT:
#if(TV_OPTION == TV_PLAY_OPTION)
			osMsgPost(SP1K_MSG_STATE_TO_STILL_PLAY);
			osMsgPost(SP1K_MSG_TV_PLUG_OUT);
#elif (TV_OPTION == TV_FULL_OPTION)
			if(sp1kVideoRecStatusGet() != VID_REC_IDLE) {
				//appVideoSnap();
				sp1kVideoRecStop();
				uiUpdateVideoStatus(0, sp1kVideoRecStatusGet());
			}
			if(sp1kVideoRecStatusGet() == VID_REC_IDLE) {
				appDispSet();
			}
#endif
			break;
		case SP1K_MSG_POWER_OFF:
		case SP1K_MSG_KEY_PRESS_POWER:
			#if 0
			if(sp1kVideoRecStatusGet() != VID_REC_RUN)
			{
				if(sp1kVideoRecStatusGet() == VID_REC_PAUSE)
				{
					appVideoSnap();
				}
				//if VID_REC_IDLE, no need to end snap process
				//20080327 suny add  start
				#if(_HW_SOLUTION_ == _HW_TK_MODEL_B_)
				sp1kHalPanelOff();
				#endif
				//20080327 suny add  end
				XBYTE[0x2030] &= ~0x02;
			}
			//if VID_REC_RUN, do nothing
			#else
			//if(sp1kVideoRecStatusGet() != VID_REC_IDLE){    //2008-7-9 mask for mantis #27979
			//	sp1kVideoRecStop();
			//}
			if(sp1kVideoRecStatusGet() == VID_REC_IDLE) {
			appPowerOffProc();
			}
			#endif
			break;
		case SP1K_MSG_MEDIA_REC_DISK_FULL:
			//show memory full
			//HAL_DispRegUpdate();
			if(sp1kVideoRecStatusGet() != VID_REC_IDLE) {
				sp1kVideoRecStop();
				uiUpdateVideoStatus(0, sp1kVideoRecStatusGet());
			}
			uiUpdateOSDMemFull();
			osMsgPost(SP1K_MSG_STATE_INIT);
			#if LIFE_SPAN_TEST
			vidClipRdy=0;
			#endif

			break;
		case SP1K_MSG_MEDIA_REC_OK:
			//update osds
		#if LIFE_SPAN_TEST
		osMsgFlush();
		osMsgPost(SP1K_MSG_KEY_PRESS_S2);
		#endif
			appVideoOsdInit();	//lryy
			appAutoOffEn(1);
			/* power control -- video preview */
			appModePowerCtrl(MODE_PREVIEW);
			uiRemainPixInit();
			break;
		//jintao.liu 2008-3-12
		//add for battery detect
		case SP1K_MSG_BAT_LV_UPDATE://jintao.liu 2008-3-13 add for battery action
			uiUpdateBatteryLevel();
			appBattStsHandle();
			break;
		case SP1K_MSG_BAT_EMPTY:
			if(sp1kVideoRecStatusGet() != VID_REC_IDLE){//2008-7-9 mantis #27979
				sp1kVideoRecStop();
				uiUpdateVideoStatus(0, sp1kVideoRecStatusGet());//2008-7-15 mantis #28057
			}

			uiUpdateOSDBatEmpty();
			osMsgPost(SP1K_MSG_POWER_OFF);
			sp1kBtnDisableAll();//ready to power off, disable all button!
			break;
		case SP1K_MSG_NAND_ERROR:
			uiOsdDialogDisp(ID_STR_CARD_ERROR, 0);
			break;
		case SP1K_MSG_CARD_ERROR:
			osMsgFlush();
			uiOsdDialogDisp(ID_STR_CARD_ERROR, 1000);
			menuProcCurrPosSet(MENU_MARK_FORMAT_YES);
			menuProcDisp();
			cardErrFmt = 1;
			break;
		case SP1K_MSG_CARD_NOT_SUPPORT:
			uiOsdDialogDisp(ID_STR_CARD_ERROR, 1000);
			sp1kBtnDisableAll();
			break;
		default:
			break;
	}

	return;
}

//-----------------------------------------------------------------------------
//appVideoViewInit
//-----------------------------------------------------------------------------
/**
 * @brief		app api for video resolution set
 * @param	initMode: 0:full init
 * @retval	NONE
 * @see
 * @author	sunyong
 * @since	2008-03-15
 * @todo
 * @bug
*/
void appVideoViewInit(UINT8 initMode) USING_0
{
	UINT8 mode, recMode, pos, fmt;
	UINT16 width;
	UINT16 height;
	UINT16 pv_width;
	UINT16 pv_height;
	uiPara_t* puiPara = appUiParaGet();

	/* power control -- video preview */
	appModePowerCtrl(MODE_PREVIEW);
	sp1kPvPhotofrmEnable(0);
	initMode = initMode;
	sp1KAWBScaleSet(SP1K_AWB_Jump_Scale, AWB_SPEED);

	#if 1  //mark for date stamp
	mode = VD_STAMP_MODE_DATE;
	recMode = VD_STAMP_REC_MODE_FST_FRAME;
       pos = VD_STAMP_RIGHT| VD_STAMP_BOTTOM;
       fmt = VD_STAMP_FMT_MMDDYYYY | VD_STAMP_FMT_HHMMSS;
//	printf("md: %bu, %bx, %bx, %bx\n", mode, recMode, pos, fmt);
      	sp1kVideoRecStampCfg(mode, pos, recMode);
       sp1kVideoRecStampDateFmtSet(fmt);
	           
       if(puiPara->VideoSize == MOV_SIZE_D1/*MOV_SIZE_VGA*/)
    		sp1kVideoRecStampImgResLoad(0, 720, 32); //back ground image
    	else if (puiPara->VideoSize == MOV_SIZE_VGA)
    		sp1kVideoRecStampImgResLoad(0, 360,32); //back ground image
    	else 	
    		sp1kVideoRecStampImgResLoad(0, 210, 20); //back ground image
	//  sp1kVideoRecStampImgResLoad(0x25, 320, 16);
	sp1kVideoRecStampStsSet(1);
#endif

#ifdef DPF_SCANNER
	puiPara->VideoSize = MOV_SIZE_VGA;
#endif
	appVideoResSet(puiPara->VideoSize);
	if(initMode == SP1K_VIDEO_VIEW_INIT_FULL) {
		sp1kVideoRecSizeGet(&width, &height);
		pvSizeGet(&pv_width, &pv_height);
		//printf("w=%d h=%d pw=%d ph=%d\n", width, height, pv_width, pv_height);
		//printf("ps1=%d ps0=%d\n", (UINT16)appPreStateGet(1), (UINT16)appPreStateGet(0));

		if ((width != pv_width) || (appPreStateGet(0) == APP_STATE_STILL_VIEW)
			||(appPreStateGet(0) == APP_STATE_STILL_PLAY)
			||(appPreStateGet(0) == APP_STATE_MUTI_PLAY)
			||(appPreStateGet(0) == APP_STATE_VIDEO_PLAY)
			||(appPreStateGet(0) == APP_STATE_AUDIO_PLAY)
			||(appPreStateGet(0) == APP_STATE_USB)
			||(appPreStateGet(0) == APP_STATE_AUDIO_REC)) {//suny modify 080325

			sp1kDispImgWinEn(0); // hlc, Mantis #0021959

			sp1kDispVsyncWait(SP1K_DISP_SIGNAL_RISING);

			sp1kAeModeSet(0);
			sp1kAwbModeSet(SP1K_AWB_MODE_DISABLE);
			sp1kPrevewSet( 1, width, height, sp1kVideoZoomFctGet(), 0);// hlc, Mantis: 0021118

			HAL_ZUpdateWait(HAL_DRAM_ZUPDATE_PV, 0);
			sp1kPvZoomSet(1, sp1kVideoZoomFctGet(), 0); // hlc, Mantis: 0021118
			sp1kAeModeSet(1);
			//sp1kAWBModeSet(SP1K_AWB_MODE_AUTO);//jintao.liu 2008-5-15 for mantis #24124

			sp1kDispImgWinEn(1); // hlc, Mantis #0021959
		}
	}
	appVideoOsdInit();	//lryy

	return;
}

//-----------------------------------------------------------------------------
//appVideoResSet
//-----------------------------------------------------------------------------
/**
 * @brief		app api for video resolution set
 * @param	res: 0:VGA ,1: QVGA
 * @retval	NONE
 * @see
 * @author	sunyong
 * @since	2008-03-15
 * @todo
 * @bug
*/
void appVideoResSet(UINT8 res) USING_0
{
	switch(res) {
		case MOV_SIZE_VGA:
			sp1kVideoRecSizeSet(vid_VGA);
			break;
		case MOV_SIZE_QVGA:
			sp1kVideoRecSizeSet(vid_QVGA);
			break;
		case MOV_SIZE_QVGA_HFR:
			sp1kVideoRecSizeSet(vid_QVGA);
			break;
		case MOV_SIZE_D1:
			sp1kVideoRecSizeSet(vid_D1);
			break;
		default:
			sp1kVideoRecSizeSet(vid_VGA);
			break;
	}

	return;
}

//-----------------------------------------------------------------------------
//appVideoPauseProcess
//-----------------------------------------------------------------------------
/**
 * @brief		app api for video pause process
 * @param	NONE
 * @retval	NONE
 * @see
 * @author	sunyong
 * @since	2008-03-15
 * @todo
 * @bug
*/
void appVideoPauseProcess(void) USING_0
{
	UINT32 time;

	if(sp1kVideoRecStatusGet() == VID_REC_PAUSE) {
		sp1kVideoRecResume();
	} else {
		time = sp1kvideoRecTimeGet();
		if(time<1000) {
			return;
		}
		sp1kVideoRecPause();
	}
	uiUpdateVideoStatus(0, sp1kVideoRecStatusGet());

	return;
}

//-----------------------------------------------------------------------------
//appVideoSnap
//-----------------------------------------------------------------------------
/**
 * @brief		app api for video snap
 * @param	NONE
 * @retval	NONE
 * @see
 * @author	sunyong
 * @since	2008-03-15
 * @todo
 * @bug
*/
void appVideoSnap(void) USING_0
{
	UINT32 time=0;

	appModePowerCtrl(MODE_VIDEOREC);
	/*cut down the panenl clock*/
		XBYTE[0x2013] = 0xFF;
	//	XBYTE[0x2014] = 0xFF;
		XBYTE[0x2015] = 0xFF;	

	if(sp1kVideoRecStatusGet() == VID_REC_IDLE) {
		uiUpdateVideoRecRemainTime(&time);
		if(time == 0) {
			osMsgPost(SP1K_MSG_MEDIA_REC_DISK_FULL);
			return;
		}
		appVideoFrmRateSet();//jintao.liu 2008-4-22
		sp1kvideoRecAudFmtSet(APP_AUDIO_FMT);
		sp1kVideoRecStart();
		if(sp1kVideoRecStatusGet() == VID_REC_RUN){
			uiUpdateVideoRecTime(0);
			printf("zhenglei...vidRec Start OK\n");
		}else {
			printf("vidRec Start err\n");
		}
	} else {
		time = sp1kvideoRecTimeGet();
		if(time<1000) {
			return;
		}
		printf("zhenglei...rec stop\n");
		sp1kVideoRecStop();
	}
		XBYTE[0x2013] = 0xEF;
	//	XBYTE[0x2014] = 0xFD;
		XBYTE[0x2015] = 0xE7;	
	uiUpdateVideoStatus(0, sp1kVideoRecStatusGet());

	return;
}

//-----------------------------------------------------------------------------
//appVideoQualitySet
//-----------------------------------------------------------------------------
/**
 * @brief	select snap quality
 * @param
 * @retval	void
 * @see
 * @author	jintao.liu
 * @since	2008-03-15
 * @todo
 * @bug
*/
UINT8 appVideoQualitySet(void)
{
	uiPara_t* uiPara;

	uiPara = appUiParaGet();
	switch(uiPara->ImageQuality)
	{
		case MOV_QUAL_SUPER:
			sp1kVideoRecQTableSet(80);
			//qt = 0;//K_Q90
			//putchar('9');
			break;
		case MOV_QUAL_FINE:
			sp1kVideoRecQTableSet(70);
			//qt = 1;//K_Q80
			//putchar('8');
			break;
		case MOV_QUAL_NORMAL:
			sp1kVideoRecQTableSet(50);
			//qt = 2;//K_Q50
			//putchar('5');
			break;
		default:
			break;
	}

	return SUCCESS;
}

//-----------------------------------------------------------------------------
//appVideoFrmRateSet
//-----------------------------------------------------------------------------
/**
 * @brief	select snap quality
 * @param
 * @retval	void
 * @see
 * @author	jintao.liu
 * @since	2008-03-15
 * @todo
 * @bug
*/
void sp1KAEParamSet(UINT8 selector, UINT16 val);
UINT8 appVideoFrmRateSet(void)
{
	uiPara_t* uiPara;


	uiPara = appUiParaGet();
	switch(uiPara->FrameRate) {
		case MOV_FRM_HIGH:
			sp1kVideoRecFrameRateSet(30);
			if(uiPara->LightFreq == PRV_FREQ_50) {
				sp1kAeParamSet(SP1K_AE_FRAME_RATE, SP1K_FRAME_RATE_25);
			}
			else {
				sp1kAeParamSet(SP1K_AE_FRAME_RATE, SP1K_FRAME_RATE_30);
			}
			break;
		case MOV_FRM_LOW:
			sp1kVideoRecFrameRateSet(15);
			if(uiPara->LightFreq == PRV_FREQ_50) {
				sp1kAeParamSet(SP1K_AE_FRAME_RATE, SP1K_FRAME_RATE_12P5);
			}
			else {
				sp1kAeParamSet(SP1K_AE_FRAME_RATE, SP1K_FRAME_RATE_15);
			}
			break;
		default:
			sp1kVideoRecFrameRateSet(30);
			if(uiPara->LightFreq == PRV_FREQ_50) {
				sp1kAeParamSet(SP1K_AE_FRAME_RATE, SP1K_FRAME_RATE_25);
			}
			else {
				sp1kAeParamSet(SP1K_AE_FRAME_RATE, SP1K_FRAME_RATE_30);
			}
			break;
	}

	return SUCCESS;
}

//-----------------------------------------------------------------------------
//videoRecKeyOnUp
//-----------------------------------------------------------------------------
/**
 * @brief		video key on up process
 * @param	NONE
 * @retval	NONE
 * @todo
 * @author	SunYong
 * @since	2007-12-18
 */
void appVideoViewTele (void) USING_0
{
	UINT16 newFact;

	ZoomCurLog	-= Video_ZOOM_LogStep;
	video_zoomInFlag = 1;

	if (ZoomCurLog > video_zoomMaxLog)
		ZoomCurLog = video_zoomMaxLog;

	newFact = 10000/ZoomCurLog;
 	if(newFact <= video_zoomMax) {
		video_zoomFactor = newFact;
		printf("fac:%d\n",video_zoomFactor);
	}
	else {
		ZoomCurLog  = video_zoomMinLog;
		video_zoomFactor = video_zoomMax;
	}
}

//-----------------------------------------------------------------------------
//videoRecKeyOnDown
//-----------------------------------------------------------------------------
/**
 * @brief		video key on down process
 * @param	NONE
 * @retval	NONE
 * @todo
 * @author	SunYong
 * @since	2007-12-18
 */
void appVideoViewWide (void) USING_0
{
	UINT16 newFact;

	if(video_zoomFactor<= video_zoomMin){
		return;
	}
	ZoomCurLog += Video_ZOOM_LogStep;
	video_zoomOutFlag = 1;
	if (ZoomCurLog < video_zoomMinLog)
		ZoomCurLog = video_zoomMinLog;

	newFact = 10000/ZoomCurLog ;
	printf("fct:%d\n",video_zoomFactor );

	if(newFact >= video_zoomMin ) {
		video_zoomFactor  = newFact;
	}
	else {
		ZoomCurLog  = video_zoomMaxLog;
		video_zoomFactor = video_zoomMin;
	}
}

